package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2023/10/16 09:45
 * @apiNote
 */

public class Test00714MaxProfit {

    public static void main(String[] args) {
        int[] prices = {1,3,2,8,4,9};
        int fee = 2;
        int count = test(prices, fee);
        System.out.println(count);
    }

    public static int test(int[] prices, int fee) {
        int n = prices.length;
        int[][] dp = new int[n][2];
        // 0   买   1  不买
        dp[0][0] = -prices[0] -fee;
        dp[0][1] = 0;
        for (int i = 1; i < n; i++) {
            dp[i][0] = Math.max(dp[i-1][0], dp[i-1][1] - prices[i] - fee);
            dp[i][1] = Math.max(dp[i-1][1], dp[i-1][0] + prices[i]);
        }
        return dp[n-1][1];
    }


}
